﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CtrlShoppingCart.ascx.cs"
    Inherits="Aij1.UserControls.CtrlShoppingCart" %>
<script type="text/javascript">
    //<!--
    var cartContainer;
    var cartItemTemplate;
    var totalCost;
    var totalCount;

    function Reserve(oid, count) {
        cartContainer = $("#divCart");
        cartItemTemplate = $("#shoppingItemTemplate");
        cartContainer.append('<div style="text-align:center;" class="tips"> 正在处理中，请稍等...</div>');
        $.ajax({
            type: "GET",
            url: "ShoppingItems.ashx",
            data: "ID=" + oid + "&Count=" + count + "&rnd=" + new Date().getUTCMilliseconds(),
            dataType: "html",
            success: function (msg) { ReloadCart(msg); },
            async: true
        });
    }

    function ReloadCart(itemStr) {
        cartContainer.empty();
        var items = itemStr.split('|');
        totalCost = 0;
        totalCount = 0;
        if (items && items.length > 0) {
            for (var i = 0; i < items.length; i++) {
                var obj = items[i].split(';');
                if (obj.length >= 4)
                    addItemToCart(obj[0], obj[1], obj[2], obj[3]);
            }
        }
        $("#TotalCost").text('￥' + totalCost);
        $("#TotalCount").text(totalCount);
    }

    function addItemToCart(oid, name, price, count) {
        var newchild = cartItemTemplate.clone();
        newchild.id = "tr" + oid;
        newchild.html(newchild.html().replace(/\{oid\}/g, oid));
        newchild.html(newchild.html().replace(/\{name\}/g, name));
        newchild.html(newchild.html().replace(/\{price\}/g, price));
        newchild.html(newchild.html().replace(/\{count\}/g, count));
        newchild.appendTo(cartContainer);
        newchild.show();
        totalCost += parseInt(price) * parseInt(count);
        totalCount += parseInt(count);
    }

    $(document).ready(function () {
        Reserve(0, 0);
    });
    //-->
</script>
您的订单:
<table width="100%" id="tbShoppingCart" style="font-size: <%=FontSize%>px">
    <tr>
        <th>
            商品名称
        </th>
        <th width="40">
            价格
        </th>
        <th width="30">
            数量
        </th>
        <th width="20">
            &nbsp;
        </th>
    </tr>
</table>
<table style="width: 100%; display: none; font-size: 12px;" id="shoppingItemTemplate">
    <tr>
        <td>
            {name}
        </td>
        <td align="right" width="40">
            {price}
        </td>
        <td align="right" width="30">
            {count}
        </td>
        <td align="center" width="20">
            <img src="../PicShow_files/bg17.png" onclick='Reserve("{oid}", "-{count}")' />
        </td>
    </tr>
</table>
<div id='divCart' style="width: 100%">
</div>
<p style="margin-top: .5em">
    总数:<span id="TotalCount">0</span> 总价:<span id="TotalCost">￥0</span></p>
<%if (ShowSubmitButton)
  { %>
<div style="text-align: center; margin-top: .5em;">
    <input id="btnSubmitCart" type="button" value="提交订单" onclick='location="SendOrder.aspx"' />
</div>
<%} %>
